package com.rd.student.jiaji.class2.shirui.test0803.petstore;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        ArrayList<Animal> dogs = new ArrayList<>();
        ArrayList<Animal> cats = new ArrayList<>();
        ArrayList<Animal> pigs = new ArrayList<>();
        ArrayList<String> descAnimals = new ArrayList<>();
        ArrayList<Store> customers = new ArrayList<>();

        Random random = new Random();
        descAnimals.add("可爱的");
        descAnimals.add("顽皮的");
        descAnimals.add("聪明的");
        descAnimals.add("漂亮的");

        for (int i = 0; i < 10; i++) {
            int indexDesc = random.nextInt(descAnimals.size());
            Dog dog = new Dog(descAnimals.get(indexDesc) + (i + 1) + "号" + "小狗");
            dogs.add(dog);
        }
        for (int i = 0; i < 5; i++) {
            int indexDesc = random.nextInt(descAnimals.size());
            Cat cat = new Cat(descAnimals.get(indexDesc) + (i + 1) + "号" + "小猫");
            cats.add(cat);
        }
        for (int i = 0; i < 3; i++) {
            int indexDesc = random.nextInt(descAnimals.size());
            Pig pig = new Pig(descAnimals.get(indexDesc) + (i + 1) + "号" + "小猪");
            pigs.add(pig);
        }

        int indexDogs = random.nextInt(dogs.size());
        int indexCats = random.nextInt(cats.size());
        int indexPigs = random.nextInt(pigs.size());


        Scanner scanner = new Scanner(System.in);
        System.out.println("输入您的登记名字");
        String name = scanner.next();
        System.out.println("输入您的联系方式");
        int phoneNumber = scanner.nextInt();

        System.out.println("选择想要购买宠物的类型");
        System.out.println("1.小狗");
        System.out.println("2.小猫");
        System.out.println("3.小猪");

        int number = scanner.nextInt();
        Lady lady = new Lady(name, phoneNumber);
        switch (number) {
            case 1:
                System.out.println("小狗列表:");
                for (int i = 0; i < dogs.size(); i++) {
                    System.out.println(dogs.get(i));
                }
                System.out.println("随机选择后信息为:");
                lady.buyPet(dogs.get(indexDogs), dogs, indexDogs);
                dogs.get(indexDogs).action();
                break;
            case 2:
                System.out.println("小猫列表:");
                for (int i = 0; i < cats.size(); i++) {
                    System.out.println(cats.get(i));
                }
                System.out.println("随机选择后信息为:");
                lady.buyPet(cats.get(indexCats), cats, indexCats);
                cats.get(indexCats).action();
                break;
            case 3:
                System.out.println("小猪列表:");
                for (int i = 0; i < pigs.size(); i++) {
                    System.out.println(pigs.get(i));
                }
                System.out.println("随机选择后信息为:");
                lady.buyPet(pigs.get(indexPigs), dogs, indexPigs);
                pigs.get(indexPigs).action();
                break;
        }

        Calendar calendar = Calendar.getInstance();

        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        String buyTime = "购买时间:" + year + "-" + month + "-" + day + "-" + minute + ":" + second;
        System.out.println(buyTime);

        if (number == 1) {
            Store store = new Store(name, phoneNumber, buyTime, dogs.get(indexPigs));
            customers.add(store);
        } else if (number == 2) {
            Store store = new Store(name, phoneNumber, buyTime, cats.get(indexPigs));
            customers.add(store);
        } else if (number == 3) {
            Store store = new Store(name, phoneNumber, buyTime, pigs.get(indexPigs));
            customers.add(store);
        }

        for (int i = 0; i < customers.size(); i++) {
            System.out.println(customers.get(i));
        }
    }
}

class Animal {
    String name;

    public Animal(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    void action() {
    }

    @Override
    public String toString() {
        return name;
    }
}

class Dog extends Animal {

    public Dog(String name) {
        super(name);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void action() {
        System.out.println(getName() + "正在摇尾巴");
    }
}

class Cat extends Animal {

    public Cat(String name) {
        super(name);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    void action() {
        System.out.println(getName() + "正在喵喵叫");
    }
}

class Pig extends Animal {

    public Pig(String name) {
        super(name);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    void action() {
        System.out.println(getName() + "正在哼哼叫");
    }
}

class Lady {
    String name;
    int number;

    public Lady(String name, int number) {
        this.name = name;
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public int getNumber() {
        return number;
    }

    public void buyPet(Object pet, ArrayList list, int index) {
        pet = list.get(index);
        System.out.println("顾客" + getName() + ",联系方式:" + getNumber() + ",购买了" + pet);
    }
}

class Store {
    String customer;
    int number;
    String time;
    Animal animal;

    public Store(String customer, int number, String time, Animal animal) {
        this.customer = customer;
        this.number = number;
        this.time = time;
        this.animal = animal;

    }

    @Override
    public String toString() {
        return "顾客信息{" +
                "姓名:" + customer + '\'' +
                ", 联系方式'" + number + '\'' +
                ", 时间:'" + time + '\'' +
                ", 购买宠物:" + animal +
                '}';
    }
}



